<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #title="{ record }">
        <a-link color="blue" @click="crudRef.editAction(record)">{{ record.title }}</a-link>
      </template>
    </ma-crud>
    <work-info ref="workInfo" />
  </div>
</template>
<script setup>
import { ref, reactive,provide } from 'vue'
import workOrder from '@/api/logistics/workOrder'
import dictHelp from "@/utils/dicthelp.js";
import WorkInfo from './info.vue'

const crudRef = ref()
const workInfo = ref()
const options = reactive({
  id: 'work_order',
  pageLayout: 'fixed',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  tabs:{
    dataIndex:'status'
  },
  // operationColumn: true,
  // operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: "70%",
    layout:[
      {
        formType: 'grid-tailwind',
        colNumber: 1,
        cols: [
          {
            formList: [
              {dataIndex: "title"},
              {dataIndex: "user_id"},
              {dataIndex: "admin"},
              {dataIndex: "user_visible"},
              {dataIndex: "remind_at"},
              {dataIndex: "remark"},
            ]
          },
        ]
      }
    ]
  },
  api: workOrder.getList,
  recycleApi: workOrder.getRecycleList,
  add: {
    show: true,
    api: workOrder.save,
    auth: ['logistics:workOrder:save']
  },
  edit: {
    show: false,
    api: workOrder.update,
    auth: ['logistics:workOrder:update'],
    action: (record)=>{
      workInfo.value.open(record)
    },
  },
  afterEdit:()=>{
    workInfo.value.refreshRecode()
  }
  // delete: {
  //   show: true,
  //   api: workOrder.deletes,
  //   auth: ['logistics:workOrder:delete'],
  //   realApi: workOrder.realDeletes,
  //   realAuth: ['logistics:workOrder:realDeletes']
  // },
  // recovery: {
  //   show: true,
  //   api: workOrder.recoverys,
  //   auth: ['logistics:workOrder:recovery']
  // }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "标题",
    dataIndex: "title",
    formType: "input",
    editDisplay:false,
    search: true,
    commonRules: {
      required: true,
      message: "请输入标题"
    }
  },
  {
    title: "用户",
    dataIndex: "user_id",
    formType: "select",
    editDisplay:false,
    dict: dictHelp.customer,
    search: true
  },
  {
    title: "关注人",
    dataIndex: "admin",
    formType: "select",
    dict: dictHelp.user,
    multiple:true,
    addDisplay:false,
    // editDisplay:false,
    hide: true
  },
  {
    title: "类型",
    dataIndex: "about_type",
    formType: "select",
    dict:{
      data:[
        {label:'运单',value:1},
        {label:'提单',value:2},
        {label:'客户账单',value:3},
        // {label:'供应商账单',value:1},
      ],
      translation:true
    },
    addDisplay:false,
    editDisplay:false,
  },
  {
    title: "关联单号",
    dataIndex: "about_id",
    formType: "input",
    addDisplay:false,
    editDisplay:false,
    search: true,
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "select",
    addDisplay:false,
    editDisplay:false,
    dict: {
      name: "workOrderStatus",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
      },
    search: true,
  },
  // {
  //   title: "拦截",
  //   dataIndex: "intercept",
  //   formType: "input",
  //   hide: true,
  //   addDisplay:false,
  //   editDisplay:false,
  //   commonRules: {
  //     required: true,
  //     message: "请输入拦截"
  //   }
  // },
  {
    title: "",
    dataIndex: "user_visible",
    formType: "checkbox",
    hide: true,
    addDisplay:false,
    dict:{
      data:[
            {label:'用户可见',value:1},
          ]
    },
  },
  {
    title:"最新消息",
    dataIndex:"log.remark",
    addDisplay:false,
    editDisplay:false,
  },
  {
    title:"消息更新时间",
    dataIndex:"log.created_at",
    addDisplay:false,
    editDisplay:false,
  },
  {
    title: "提醒时间",
    dataIndex: "remind_at",
    formType: "date",
    addDisplay:false,
    // editDisplay:false,
    showTime: true
  },
  {
    title: "创建人",
    dataIndex: "created_by",
    formType: "select",
    dict: dictHelp.user,
    addDisplay: false,
    editDisplay: false,
  },

  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "描述",
    dataIndex: "remark",
    formType: "textarea",
    hide: true,
    commonRules: {
      required: true,
      message: "请输入描述"
    }
  }
])
provide('WorkOrder',crudRef)
</script>
<script> export default { name: 'logistics:workOrder' } </script>